﻿@namespace BlazorCharts
@inherits ElementSeries<TData>
@typeparam TData

@if (Chart.IsInit)
{
    <g class="bc-bar-series" transform="translate(@Rect.LT.ToPoint())">
        @{
            for (int i = 0; i < SeriesData.Groups.Count; i++)
            {
                var group = SeriesData.Groups[i];

                var color = (group ?? "Bar").RandomColor().Transparent().ToHtml();
                var colorStroke = (group ?? "Bar").RandomColor().Deepen().ToHtml();

                //分组偏移的位置
                var groupOffset = (double)(i + GroupSerialNumber) / Chart.BcSeriesGroup.GroupKeepCount * Chart.BcSeriesGroup.CategoryKeepWidth;

                @foreach (var category in SeriesData.CategoryDatas)
                {
                    var categoryX = (Chart.BcAxisGroup.AxesX.Rect.W * category.ZeroOffsetRatio);

                    var categoryStart = categoryX - Chart.BcSeriesGroup.CategoryKeepWidth / 2;

                    var groupX = categoryStart + groupOffset;

                    var data = SeriesData.GetValueData<SingleValueData>(category.Name, group);

                    var bar = new Rect();
                    bar.H = GetHeightByValue(data.Value);
                    bar.W = (int)Chart.BcSeriesGroup.GroupWidth;
                    bar.L = (int)groupX;
                    bar.B = Rect.H;

                    <rect x="@bar.X" y="@bar.Y" width="@bar.W" height="@bar.H" fill="@color" stroke="@colorStroke" stroke-width=1
                          class="bc-column-translate" />
                }
            }
        }
    </g>
}


<style>
    .bc-column-translate {
        animation-name: bc-column-animation;
        animation-duration: 1s
    }

    @@keyframes bc-column-animation {
        from {
            height: 0px;
            y: @Rect.H
            }
    }
</style>
